package com.linkage.common.controller;

import cn.hutool.core.date.DateUtil;
import com.linkage.common.util.WebToolUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/*  *
 * @describe:  类型描述 环境升级查看
 * @author shaofeng.cheng
 * @title
 * @date 2020/4/22 9:44
 * @param
 * @return
 * @version: V1.0
 */
@RestController
@RequestMapping("/common")
public class CommonSysController {

    /**  服务启动时间 */
    private static final String SYS_START_TIME = getNowDateTime();
    /**  服务名 */
    @Value("${spring.application.name}")
    private String applicationName;


    @RequestMapping(value = "/info",method = RequestMethod.GET)
    @ResponseBody
    public String info(HttpServletRequest request) {
        StringBuilder sb = new StringBuilder();
        sb.append("最新升级需求：").append(applicationName).append("<br/>");
        sb.append("最新升级时间：").append(SYS_START_TIME).append("<br/>");
        sb.append("最新升级机器：").append(getIpAddress()).append("<br/>");
        sb.append("访问者IP：").append(WebToolUtils.getIpAddress(request)).append("<br/>");
        sb.append("当前时间：").append(getNowDateTime()).append("<br/>");
        return sb.toString();
    }

    /*  *
     * @describe:  类型描述 获取IP地址
     * @author shaofeng.cheng
     * @title
     * @date 2020/4/22 9:37
     * @param
     * @return
     * @version: V1.0
     */
    public static String getIpAddress(){
        return WebToolUtils.getLocalIP();
    }
    public static String getNowDateTime(){
        return DateUtil.formatDateTime(DateUtil.date());
    }




}
